package com.jjc.android.adapter

import android.view.View
import com.jjc.android.R
import com.jjc.android.entity.SecondaryClassifyDto
import com.zhpan.bannerview.BaseBannerAdapter
import com.zhpan.bannerview.BaseViewHolder

class HomeProductAdapter : BaseBannerAdapter<SecondaryClassifyDto>() {

    var pageSelectPosition = 0
    private var pageRealSelectPosition = -1

    override fun bindData(
        holder: BaseViewHolder<SecondaryClassifyDto>?,
        data: SecondaryClassifyDto?,
        position: Int,
        realPosition: Int,
        pageSize: Int
    ) {
        holder?.setText(R.id.productNameTxt,data?.ribhfqebw2sqjovu)
        holder?.setText(R.id.prductSubTxt,data?.uegppievxbdphngo)
        if(pageRealSelectPosition==realPosition){
            if(pageRealSelectPosition==-1){
                pageRealSelectPosition = realPosition
            }
            holder?.setVisibility(R.id.tagImage, View.VISIBLE)
        }else{
            holder?.setVisibility(R.id.tagImage, View.GONE)
        }
    }

    fun onPageSelected(position: Int){
        val temp = pageRealSelectPosition
        pageSelectPosition = position%mList.size
        pageRealSelectPosition = position
        notifyItemChanged(position)
        notifyItemChanged(temp)
    }

    fun getSelected():SecondaryClassifyDto?{
        if(mList.isNullOrEmpty()||mList.size<=pageSelectPosition) return null
        return mList[pageSelectPosition]
    }

    override fun getLayoutId(viewType: Int): Int = R.layout.item_home_product
}